<template>
    <div>
 <table  class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">Id</td>
                    <td><input type="text" v-model="res.id" disabled></td>
                </tr>

                <tr>
                    <td align="right">编号</td>
                    <td><input type="text" v-model="res.code" disabled></td>
                </tr>

                <tr>
                    <td align="right">名称</td>
                    <td><input type="text" v-model="res.name"></td>
                </tr>

                <tr>
                   

                    <td align="right">类型</td>
                    <td>
                         <select v-model="res.djid">
            <option value="">请选择</option>
            <option :value="item.id" v-for="item in Xlk":key="item.id">{{item.memberLevelName  }}</option>
        </select>
                    </td>
                </tr>

                <tr>
                    <td align="right">时间</td>
                    <td><input type="date" v-model="res.time"></td>
                </tr>

                <tr>
                    <td align="right">状态</td>
                    <td>
                        <input type="radio" :value="1" v-model="res.state">冻结
                        <input type="radio" :value="2" v-model="res.state">解冻
                    </td>
                </tr>

                <tr>
                    <td></td>
                    <td><input type="button" value="修改" @click="UpdateShop()" class="btn btn-success"></td>
                </tr>
            </tbody>
        </table>

    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import {ref,onMounted} from 'vue'
import moment from 'moment';
import { useRoute,useRouter } from 'vue-router';
let router=useRouter();
let route=useRoute();



let res:any=ref({
    "id": "",
    "code": "",
    "name": "",
    "sex": "",
    "tel": "",
    "time": "",
    "state": "",
})
onMounted(()=>{
    
    Date();//商品修改方法

    ShopXlk();
})



let Xlk:any=ref([]);//下拉框

//下拉框
const ShopXlk=()=>{
    axios({
        url:'https://localhost:7000/api/Member/MemberLevel',
        method:'get',
    })
     .then((res)=>{
        console.log(res);
        Xlk.value=res.data;
    })
    .catch((err)=>{
        console.log(err);
    })
}





const Date=()=>{
    axios({
        url:'https://localhost:7000/api/Member/FanMember',
        method:'get',
        params:{
            id:route.query.id
        }
    })
     .then((ress)=>{
        console.log(ress);
        Object.assign(res.value,ress.data)
        res.value.time=moment(ress.data.time).format("YYYY-MM-DD")
    })
    .catch((err)=>{
        console.log(err);
    })
}




//商品修改方法
const UpdateShop=()=>{

if(res.value.pName=="")
{
    alert("名称不能为空");
    return;
}

if(res.value.djid=="")
{
    alert("类型不能为空");
    return;
}

if(res.value.creteTime=="")
{
    alert("时间不能为空");
    return;
}

    axios({
        url:'https://localhost:7000/api/Member/Update',
        method:'put',
        data:res.value,
    })
     .then((res)=>{
        console.log(res);
        if(res.data==-1)
        {
            alert("名称重复了")
            return;
        }
        if(res.data>0)
        {
            alert("修改成功")
            return;
        }
        else{
             alert("修改失败")
            return;
        }
        
    })
    .catch((err)=>{
        console.log(err);
    })

}



</script>

<style scoped>

</style>